Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

471
Views
AssertionError [ERR_ASSERTION]: you must pass Joi as an argument

How do I solve this Joi problem(Using express, joi@17.4.2,joi-objectid@2.0.0, ,mongoose) I am trying to link two mongoose schemas using ref as

{
...
   enroledcourses: [{
        type: Schema.Types.ObjectId,
        ref: "courses"
    }]
}

joi validation

...    
enroledcourses: Joi.array().items(Joi.ObjectId()).required()

the course collection is fine i have imported it at index.js as below

const Joi = require("joi")
Joi.objectId = require("joi-objectid")(Joi);

but i end up getting this error enter image description here

AssertionError [ERR_ASSERTION]: you must pass Joi as an argument at joiObjectId (D:\Programing projects\2021\ikodeafrika\ikodeafrikabackend\node_modules\joi-objectid\index.js:6:3) at Object. (D:\Programing projects\2021\ikodeafrika\ikodeafrikabackend\index.js:2:39)

index.js:2:39 being the joi.objectId import above plus i'm getting this when i hover over the joi.objectId import statement

Property 'objectId' may not exist on type 'Root'. Did you mean 'object'?ts(2568) index.d.ts(1998, 9): 'object' is declared here. any

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is because joi-objectid@2.0.0 is not compatible with joi@17.4.2.

Fix:
Upgrade joi-objectid to v4.0.2

About the Typescript error (Property 'objectId' may not exist on type 'Root'), you need to augment the type of Joi to add the objectId property. This can be done by creating a declaration file:

// src/types/joi.d.ts
import { Schema } from "joi";

declare module "joi" {
  interface Root {
    objectId(): Schema;
  }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!